<template>
  <div>
  <div style="background: #59447c;padding: 20px 12px;box-sizing: border-box;width: 100%;" :key="'ling1991'">
    <gu_scale :scale="randScale" @swiperLover="swiperLover" name="year" ref="yearScale"
    borderColor="#c353ff"
    ></gu_scale>
  </div>

</div>
</template>

<script>
  import gu_scale from "./gu_scale.vue"
  import {weightMethods,heightMethods,yearMrthods} from "@/api/scale_data.js"
  export default{
    name:"index",

    data(){
      return{
        scale:[],
        scale1:[],
        scale2:[],
        randScale:[],
      }
    },
    methods:{
      swiperLover(direction,item,name){
        console.log("change",item)
        let scale = this.randScale
        let dataInd = item.id
        let maxLen = this.scale.length
        let ind = 0
        //
        if(dataInd <5 || (dataInd >= (maxLen - 5))){
          return false
        }
        if(direction == 'prev'){ //往回滚动
          if(dataInd>=60){ //长度大于60的时候
            dataInd  = dataInd - 50
            ind = 50
          }else{
            ind = dataInd //比如滚动到30 这时候只剩下20条数据 这时候加载的是 0-60 index是item.id 也就是30
            dataInd = 0

          }

        }
        if(direction == "next"){ //往右滚动
          let maxValue = maxLen - item.id
          if(maxValue>=60){ //长度大于60条
            dataInd  = dataInd - 10
            ind = 10
          }else{
            let startVal =  maxLen - 60
            ind = dataInd - startVal
            dataInd = startVal
            if(ind<=9){ //补全当前选中的ind前面没有刻度
              ind = ind - 10
              dataInd = dataInd - 10
            }
          }

        }
        let data = this.scale
        let newData = this.getScaleData(data,dataInd)
        this.randScale = newData
        this.$nextTick(()=>{
          this.$refs.yearScale.slideToIndex(ind)
        })
      },
      getScaleData(data,dataInd){
        let arr = []
        for(let i = 0; i<60;i++){
          let ind = i + dataInd
          arr.push(data[ind])
        }
        return arr
      }
    },

    mounted(){
     let scale = heightMethods()
     this.scale = scale
     let randScale = []
     for(let i = 0;i<60;i++){
       randScale.push(scale[i])
     }
     this.randScale = randScale
    },
    components:{
      gu_scale
    }
  }
</script>

<style>
</style>
